home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Snippets
/
PNL Libraries
/
MyInterruptSafeDebug.p
< prev
next >
Wrap
Text File
|
1997-01-29
|
3KB
|
149 lines
unit MyInterruptSafeDebug;
interface
uses
Types;
procedure StartupInterruptSafeDebug;
procedure InterruptSafeDebug (const s: Str255);
procedure InterruptSafeDebugChar (ch: char);
implementation
uses
Fonts,Quickdraw,Memory,Windows,MyLowLevel,MyTypes, MyMemory, MyStartup;
const
debug = true;
const
ourfont = geneva;
oursize = 9;
ourheight = 10;
ourdescent = 2;
max_pixelsize = 8;
ourrows = 12;
our_magic = $12435687;
type
CharArray = packed array[char, 1..ourheight, 1..max_pixelsize] of Byte;
const
WMgrPort = $9DE;
type
GrafPtrPtr = ^GrafPtr;
var
baseaddr: Ptr;
rowbytes: integer;
pixelsize: integer;
ourchars: ^CharArray;
pos, count: integer;
row: integer;
magic: longint;
procedure InterruptSafeDebugChar (ch: char);
procedure Plot (ch: char);
var
h, c: integer;
begin
for h := 1 to ourheight do begin
for c := 1 to pixelsize do begin
AddPtrLong(baseaddr, longint(h - 1 + row * ourheight) * rowbytes + pos * pixelsize + c - 1)^ := SignedByte(ourchars^[ch, h, c]);
end;
end;
end;
begin
if debug then begin
if magic <> our_magic then begin
DebugStr('BANG!');
end;
Plot(ch);
pos := (pos + 1) mod count;
if pos = 0 then begin
row := (row + 1) mod ourrows;
end;
Plot('•');
end;
end;
procedure InterruptSafeDebug (const s: Str255);
var
i: integer;
begin
if debug then begin
if s = '' then begin
InterruptSafeDebugChar('*');
end else begin
for i := 1 to length(s) do begin
InterruptSafeDebugChar(s[i]);
end;
InterruptSafeDebugChar('.');
end;
end;
end;
function InitInterruptSafeDebug(var msg: integer): OSStatus;
var
wp: WindowPtr;
r: Rect;
i, h, c: integer;
ch: char;
junk: OSErr;
begin
{$unused(msg)}
{ DebugStr( 'InitInterruptSafeDebug;g' );}
if debug then begin
magic := our_magic;
junk := MNewPtr(ourchars, SizeOf(CharArray));
SetRect(r, 0, 40, 100, 100);
wp := NewCWindow(nil, r, '', true, 0, POINTER(-1), false, 0);
SetPort(wp);
TextFont(ourfont);
TextSize(oursize);
baseaddr := CGrafPtr(wp)^.portPixMap^^.baseAddr;
pixelsize := CGrafPtr(wp)^.portPixMap^^.pixelSize;
rowbytes := BAND(CGrafPtr(wp)^.portPixMap^^.rowBytes, $3FFF);
r := GetQDGlobals^.screenBits.bounds;
for ch := chr(0) to chr(255) do begin
SetRect(r, 0, 0, 100, 100);
EraseRect(r);
MoveTo(0, ourheight - ourdescent);
DrawChar(ch);
for h := 1 to ourheight do begin
for c := 1 to pixelsize do begin
ourchars^[ch, h, c] := BAND(AddPtrLong(baseaddr, longint(40 + h - 1) * rowbytes + c - 1)^, $FF);
end;
end;
end;
DisposeWindow(wp);
SetPort(GrafPtrPtr(WMgrPort)^);
r := GetQDGlobals^.screenBits.bounds;
OffsetPtr(baseaddr, longint(r.bottom - r.top - ourheight * ourrows) * rowbytes);
r.top := r.bottom - ourheight * ourrows;
EraseRect(r);
pos := 0;
row := 0;
count := (r.right - r.left) div 8 - 2;
for i := 1 to count * ourrows do begin
InterruptSafeDebugChar(' ');
end;
end;
InitInterruptSafeDebug := noErr;
end;
procedure FinishInterruptSafeDebug;
begin
if debug then begin
MDisposePtr(ourchars);
end;
end;
procedure StartupInterruptSafeDebug;
begin
SetStartup(InitInterruptSafeDebug, nil, 0, FinishInterruptSafeDebug);
end;
end.